package com.certification.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.certification.common.utils.Constant;
import com.certification.entity.SchoolInvestigate;
import com.certification.service.SchoolInvestigateService;
import com.certification.service.SysUserRoleService;
import com.certification.vo.PageVO;
import com.certification.vo.ResponseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author copa
 * @createDate 2022-03-29 23:07
 * @function
 */
@RestController
@Api(tags = {"流程：进校考察"})
public class SchoolInvestigateController extends AbstractController {

    @Resource
    private SchoolInvestigateService schoolInvestigateService;

    @Resource
    private SysUserRoleService sysUserRoleService;

    @GetMapping("admin/investPage/{certId}")
    @ApiOperation(value = "查看考察分页(认证专家)")
    public ResponseMessage<Page<SchoolInvestigate>> getInvestDetailAdminPage(@PathVariable Integer certId, PageVO pageVO) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return schoolInvestigateService.getInvestDetailAdminPage(certId, pageVO);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

    @GetMapping("admin/invest/{certId}/{investId}")
    @ApiOperation(value = "查看考察详情(认证专家)")
    public ResponseMessage<SchoolInvestigate> getInvestDetailAdmin(@PathVariable("certId") Integer certId,
                                                                   @PathVariable("investId") Integer investId) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return schoolInvestigateService.getInvestDetailAdmin(certId, investId);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

    @PutMapping("admin/invest")
    @ApiOperation(value = "判定认证是否通过：第三阶段")
    public ResponseMessage<String> putInvestAdmin(@RequestParam @ApiParam("认证id") Integer certId,
                                    @RequestParam @ApiParam("同意-1 驳回-2") Integer status,
                                    @RequestParam(required = false) @ApiParam("若通过写备注，若驳回写理由") String remark) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return schoolInvestigateService.putInvestAdmin(certId, status, remark);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

}
